/**
 * Project Name:jh
 * File Name:SocketUtils.java
 * Package Name:com.jh.utils
 * Date:下午5:32:58
 * Copyright (c) 2021, LZ All Rights Reserved.
 *
*/

package com.jh.utils;

import java.util.Properties;
import java.util.concurrent.ArrayBlockingQueue;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Description: <br/>
 * Date: 下午5:32:58 <br/>
 * 
 * @author lz E-mail:withitren@outlook.com
 * @version
 * @see
 */
public class BlockingQueueUtils {
    static final Logger logger = LoggerFactory.getLogger(BlockingQueueUtils.class);

    private BlockingQueueUtils() {

    }

    private static ArrayBlockingQueue<String> rxBq = null;

    private static ArrayBlockingQueue<String> txBq = null;

    private static BlockingQueueUtils instance = null;

    public static BlockingQueueUtils getInstance() {
        if (instance == null) {
            init();
            instance = new BlockingQueueUtils();
        }
        return instance;
    }

    public ArrayBlockingQueue<String> getrxBq() {
        return rxBq;
    }

    public ArrayBlockingQueue<String> gettxBq() {
        return txBq;
    }

    private static void init() {
        Properties prop = new Properties();
        try {
            prop.load(BlockingQueueUtils.class.getResourceAsStream("/appConfig.properties"));
            // throw new Exception("OK!");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        String rxCapacity = prop.getProperty("rxCapacity", "9");
        String txCapacity = prop.getProperty("txCapacity", "9");
        int rxCapacityInt = Integer.parseInt(rxCapacity);
        int txCapacityInt = Integer.parseInt(txCapacity);
        System.out.println("rxCapacityInt: " + rxCapacityInt + " txCapacityInt: " + txCapacityInt);
        logger.debug("--->" + "rxCapacity: " + rxCapacity + "  txCapacity: " + txCapacity);

        rxBq = new ArrayBlockingQueue<String>(rxCapacityInt);

        txBq = new ArrayBlockingQueue<String>(txCapacityInt);
    }

    /*test*/
    public static void main(String[] args) {
        init();

    }
}
